﻿using System;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace Gugu.management.AutoIT
{
    public enum IEStatus
    {
        Running,
        Off
    }

    public class IE
    {
        const string Name = "IE.exe";
        public IEStatus Status;
        public int Handle = -1;
        public Process Process;

        public string Address = "www.facebook.com";

        public IE()
        {
            Status = IEStatus.Off;
        }

        public bool Start()
        {
            var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            if (dir.Parent == null) return false;
            var fileName = Path.Combine(dir.Parent.FullName,"Scripts", Name);
            Process = Process.Start(fileName, Address);
            if (Process == null) return false;
            while (!Process.HasExited)
            {
                Thread.Sleep(50);
            }
            Handle = Process.ExitCode;
            Status = IEStatus.Running;
            return true;
        }

        public bool Terminate()
        {
            return true;
        }

    }
}
